﻿using System;
using Abp.Runtime.Validation;
using pandx.Mulan.Dto;

namespace pandx.Mulan.Books.Dto
{
    public class ObtainBooksInput:PagedSortedAndFilteredInput,IShouldNormalize
    {
        public DateTime StartTime { get; set; }

        public DateTime EndTime { get; set; }

        public void Normalize()
        {
            if (string.IsNullOrEmpty(Sorting))
            {
                Sorting = "Book.CreationTime DESC";
            }
            else if (Sorting.Contains("CreatorUserName", StringComparison.OrdinalIgnoreCase))
            {
                Sorting = "User.UserName";
            }
            else if (Sorting.Contains("CreatorName", StringComparison.OrdinalIgnoreCase))
            {
                Sorting = "User.Name";
            }
            else
            {
                Sorting = "Book." + Sorting;
            }

            Filter = Filter?.Trim();
        }
    }
}
